package Servlet;

import Dao.doctorDaoImpl;
import bean.Doctor;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/ChooseDoctorServlet")
public class ChooseDoctorServlet extends BaseServlet{
    protected void GetDoctors(HttpServletRequest req, HttpServletResponse resp) throws Exception {
//         <option value="1" selected >内科</option>
//                <option value="2">外科</option>
//                <option value="3">妇产科</option>
//                <option value="4">儿科</option>
//                <option value="5" >眼科</option>
//                <option value="6">口腔科</option>
//                <option value="7">皮肤科</option>
//                <option value="8">传染病科</option>
//                <option value="9">精神科</option>
//                <option value="10">影像科</option>
//                <option value="11" >麻醉科</option>

        String value  =  req.getParameter("department");
        String department = null;
        switch (value) {
            case "1":
                // 当expression的值等于value1时执行
                //statements;
                department = "内科";
                break;
            case "2":
                department = "外科";
                break;
            case "3":
                department = "妇产科";
                break;
            case "4":
                department = "儿科";
                break;
            case "5":
                department = "眼科";
                break;
            case "6":
                department = "口腔科";
                break;
            case "7":
                department = "皮肤科";
                break;
            case "8":
                department = "传染病科";
                break;
            case "9":
                department = "精神科";
                break;
            case "10":
                department = "影像科";
                break;
            case "11":
                department = "麻醉科";
                break;
        }
        req.setAttribute("office",department);
        doctorDaoImpl doctorDao = new doctorDaoImpl();
        List<Doctor> doctorList = doctorDao.queryDoctorsByDepartment(department);
        req.setAttribute("doctorList",doctorList);
        req.getRequestDispatcher("/ChooseDoctor.jsp").forward(req,resp);
    }
}
